/**

 @Name：layuiAdmin 社区系统
 @Author：star1029
 @Site：http://www.layui.com/admin/
 @License：LPPL
    
 */


layui.define(['table', 'form'], function(exports){
  var $ = layui.$
  ,admin = layui.admin
  ,view = layui.view
  ,table = layui.table
  ,setter = layui.setter
  ,form = layui.form;
  //主题管理
  table.render({
    elem: '#LAY-app-forum-list'
    ,url: layui.setter.api+'news/news'  //模拟接口
    ,where:{'access_token':layui.data(setter.tableName, {
        key: setter.request.tokenName
      })}
    ,cols: [[
      {field: 'id',title: 'ID', sort: true,width:60}
      ,{field: 'today', title: '今天'}
      ,{field: 'stime', title: '开始时间'}
      ,{field: 'subtime', title: '提交时间'}
      ,{field: 'errors', title: '错题'}
      ,{field: 'over', title: '完成时间'}
      ,{title: '操作', align: 'center', fixed: 'right', toolbar: '#table-forum-list'}
    ]]
    ,page: true
    ,limit: 20
    ,limits: [20, 40, 60, 80, 100]
    ,text: '对不起，加载出现异常！'
  });
  
  //监听工具条
  table.on('tool(LAY-app-forum-list)', function(obj){
    var data = obj.data;
    if(obj.event === 'del'){
      layer.confirm('确定删除此条文章？', function(index){
          admin.req({
              url: layui.setter.api+'news/news'
              ,data: {'id':data.id,'opt':'del'}
              ,method:'post'
              ,success: function(data){
                  if(data.code == 0){
                      obj.del();
                  }
              }
          });

        layer.close(index);
      });
    }
  });

  
  exports('news', {})
});